﻿using Liu_Project.Dal.Admin;
using LSL.SqlClient;
using Newtonsoft.Json;
using System.Data;
using Liu_Project.Utils;

namespace Liu_Project.Web.Admin.Handler.BaseHand
{
    /// <summary>
    /// MenuHand 的摘要说明
    /// </summary>
    public class MenuHand : HandlerBaseAsync
    {
        private readonly EntMenuDal dal = new EntMenuDal();

        public void GetMenuList()
        {
            _logOperation = "获取菜单导航栏";

            var data = dal.GetMenuList();

            _context.Response.Write(CommonFunction.SuccessJson(data));
        }

        public void InitData()
        {
            _logOperation = "权限菜单-获取按钮组";

            string menuCode = DataConvert.ToString(_context.Request["MenuCode"], "0");

            var data = dal.GetMenuLevel_2List(menuCode);

            _context.Response.Write(CommonFunction.SuccessJson(data));
        }

        public void LoadPage()
        {
            _logOperation = "菜单管理-获取列表数据";

            string _data = DataConvert.ToString(_context.Request["Data"], "[]");

            var _Data = JsonConvert.DeserializeObject<DataTable>(_data);
            if (_Data.Rows.Count == 0)
            {
                _context.Response.Write(CommonFunction.SuccessJson(null, 0, "请选择节点."));
                return;
            }

            var sqlWhere = ExpressionMethod.GetSqlWhere(_context);

            var data = dal.GetMenuManagementList(_Data, sqlWhere, "", "", page, pageSize, ref total);

            _context.Response.Write(CommonFunction.SuccessJson(data, total));
        }

        public void UpdateMenuVisiable()
        {
            _logOperation = "菜单管理-停用/启用";

            var _IsVisiable = DataConvert.ToInt(_context.Request["IsVisiable"], 0);
            var _Data = DataConvert.ToString(_context.Request["Data"], "0");

            var count = dal.UpdateMenuVisiable(_Data, _IsVisiable);

            _context.Response.Write(CommonFunction.SuccessJson(count));
        }

        public void UpdateMenu()
        {
            _logOperation = "菜单管理-修改";

            var _Data = DataConvert.ToString(_context.Request["Data"], "0");
            var _entMenu = Newtonsoft.Json.JsonConvert.DeserializeObject<Entity.Admin.EntMenu>(_Data);

            dal.UpdateMenu(_entMenu);

            _context.Response.Write(CommonFunction.SuccessJson());
        }

    }
}